x11: Make sure stream stays alive long enough
authorBenjamin Otte <otte@redhat.com>
Fri, 5 Jul 2019 18:55:54 +0000 (20:55 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 5 Jul 2019 19:17:00 +0000 (21:17 +0200)
When unreffing the stream from a different thread, the close function
will schedule its cleanup asynchornously in the main thread.
We need to make sure the stream object stays alive for as long as
that hasn't happened, so ref() it.

Fixes #2003

gdk/x11/gdkselectionoutputstream-x11.c

index c43e513ab3fed137da940497a419eda7688eb46f..63d1c33d17408257a494481dcdd4791d07b91656 100644 (file)
@@ -503,6 +503,7 @@ gdk_x11_selection_output_stream_invoke_close (gpointer stream)
   g_signal_handlers_disconnect_by_func (priv->display,
                                         gdk_x11_selection_output_stream_xevent,
                                         stream);
+  g_object_unref (stream);
 
   return G_SOURCE_REMOVE;
 }
@@ -512,7 +513,7 @@ gdk_x11_selection_output_stream_close (GOutputStream  *stream,
                                        GCancellable   *cancellable,
                                        GError        **error)
 {
-  g_main_context_invoke (NULL, gdk_x11_selection_output_stream_invoke_close, stream);
+  g_main_context_invoke (NULL, gdk_x11_selection_output_stream_invoke_close, g_object_ref (stream));
 
   return TRUE;
 }